/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};


  // 开启前置代理，为了拿到反向代理的真实ip
  config.proxy = true;

  // 数据库连接
  config.mysql = {
    // database configuration
    client: {
      // host
      host: 'localhost',
      // port
      port: '3306',
      // username
      user: 'root',
      // password
      password: '123456',
      // database
      database: 'blog',
    },
    // load into app, default is open
    app: true,
    // load into agent, default is close
    agent: false,
  };

  config.security = {
    csrf: {
      enable: false,
      domainWhiteList: [ 'http://admin.codemobile.cn', 'http://www.codemobile.cn' ],
      // domainWhiteList: [ '*' ],
    },
  };

  config.cors = {
    origin: ctx => {
      const allowOrigin = [
        'http://admin.codemobile.cn',
        'http://www.codemobile.cn',
        'http://localhost:3000',
        'http://localhost:3001',
      ];
      const origin = ctx.request.header.origin;
      if (allowOrigin.indexOf(origin) !== -1) {
        return origin;
      }
      return '';
    },
    credentials: true, // 允许Cookies可以跨域
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };

  // config.session = {
  //   key: 'SESSION_ID', // 设置session key,cookie里面的key
  //   maxAge: 2000, // 有效时间
  //   httpOnly: true, // 是否允许js访问session,默认为true,表示不允许js访问
  //   encrypt: true, // 是否加密
  //   renew: true, // 重置session的过期时间，延长session过期时间
  // };


  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1583806804119_6639';

  // add your middleware config here
  config.middleware = [ 'blogauth' ];
  config.blogauth = {
    enable: true,
    match: [ '/blog' ],
    threshold: 1024,
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
